#include "Engine/Math/Array1.h"
#include "Engine/Simulation/PointParallelHashGridSearcher2.h"

#include <gtest/gtest.h>

using namespace Engine;

TEST(PointParallelHashGridSearcher2, ForEachNearbyPoint) {
	Array1<Vector2D> points = {
		Vector2D(1, 3),
		Vector2D(2, 5),
		Vector2D(-1, 3)
	};

	PointParallelHashGridSearcher2 searcher(4, 4, std::sqrt(10));
	searcher.build(points.accessor());

	searcher.forEachNearbyPoint(
		Vector2D(0, 0),
		std::sqrt(10.0),
		[&points](size_t i, const Vector2D& pt) {
		EXPECT_TRUE(i == 0 || i == 2);

		if (i == 0) {
			EXPECT_EQ(points[0], pt);
		}
		else if (i == 2) {
			EXPECT_EQ(points[2], pt);
		}
	});
}

TEST(PointParallelHashGridSearcher2, ForEachNearbyPointEmpty) {
	Array1<Vector2D> points;

	PointParallelHashGridSearcher2 searcher(4, 4, std::sqrt(10));
	searcher.build(points.accessor());

	searcher.forEachNearbyPoint(
		Vector2D(0, 0),
		std::sqrt(10.0),
		[](size_t, const Vector2D&) {
	});
}

